<?php

namespace WechatSDK\Components;

use WechatSDK\Lib\Tools;

require_once ('Common.php');

/**
 * 微信菜单组件
 * @author guibinyu
 * @date 2017-06-15 04:14:50
 */
class Menu extends Common
{
     /** 创建自定义菜单 */
    const MENU_ADD_URL = '/menu/create?';
    /* 获取自定义菜单 */
    const MENU_GET_URL = '/menu/get?';
	function __construct($appid,$secret,$token)
	{
        parent::__construct($appid,$secret,$token);
	}

	function __destruct()
	{
        
	}
	public function createMenu($menu)
	{
        $this->throwAccessTokenError();
//        $menus = json_encode($menu,JSON_UNESCAPED_UNICODE);
        $menus = Tools::json_encode($menu);
        $result = Tools::httpPost(self::API_URL_PREFIX . self::MENU_ADD_URL . "access_token={$this->access_token}",$menus);
        $result = $this->parsing($result);
        return $result;
	}

	public function getMenu()
	{
        $this->throwAccessTokenError();
        $result = Tools::httpGet(self::API_URL_PREFIX . self::MENU_GET_URL . "access_token={$this->access_token}");
        $result = $this->parsing($result);
        return $result;
	}

}
?>